package com.heiyu.controller.config;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author：puremancw
 * @Description：  线上关闭接口入口
 * @Date：Create in 13:01 2017/10/12
 * @Modified by：
 */
@Configurable
@EnableSwagger2
@Component(value = "swaggerConfig")
public class SwaggerConfig {
    //如果Controller层按业务划分多个子包，那么这里需要配置多个@Bean。

    @Bean
    public Docket pincaiHelpApi() {

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(pincaiHelpApiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.heiyu.controller"))
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .build()
                .directModelSubstitute(org.joda.time.LocalDate.class, java.sql.Date.class)
                .directModelSubstitute(org.joda.time.DateTime.class, java.util.Date.class);
    }

    private ApiInfo pincaiHelpApiInfo() {
        return new ApiInfoBuilder()
                .title("链码后台API文档")
                .version("3.0")
                .build();
    }
}
